package typeConversion

import (
	"errors"
	"fmt"
	"strconv"
	"time"
)

//in string、int、float、time.time
func ToString(p_st interface{}) (string, error) {
	if p_st == nil {
		return "", errors.New("too.typeConversion ToInt err: Parameters not supported, Parameters is nil")
	}
	switch p_st.(type) {
	case string:
		return p_st.(string), nil
	case int:
		return strconv.FormatInt(int64(p_st.(int)), 10), nil
	case int32:
		return strconv.FormatInt(int64(p_st.(int32)), 10), nil
	case int64:
		return strconv.FormatInt(p_st.(int64), 10), nil
	case float32:
		return strconv.FormatFloat(float64(p_st.(float32)), 'f', -1, 32), nil
	case float64:
		return strconv.FormatFloat(p_st.(float64), 'f', -1, 64), nil
	case time.Time:
		return p_st.(time.Time).Format("2006-01-02 15:04:05"), nil
	default:
		return "", errors.New("too.typeConversion ToString err: Parameters not supported,The parameter type is " + fmt.Sprintf("%T", p_st))
	}

}
